package com.dt76.smallloanbackendservice.service.xiaohao.impl;

import com.dt76.smallloanbackendservice.mapper.xiaohao.BorrowOrderMapper;
import com.dt76.smallloanbackendservice.pojo.xiaohao.BorrowOrder;
import com.dt76.smallloanbackendservice.pojo.xiaohao.BorrowOrderQuery;
import com.dt76.smallloanbackendservice.service.xiaohao.BorrowOrderService;
import com.dt76.smallloanbackendservice.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BorrowOrderServiceImpl implements BorrowOrderService {

    @Autowired
    private BorrowOrderMapper borrowOrderMapper;

    @Override
    public Page qryAllOrder(Integer currentPageNo) {
        Page page = new Page();
        page.setPageIndex(currentPageNo);
        page.setTotalCount(borrowOrderMapper.qryCount());
        page.setRows(borrowOrderMapper.qryAllOrder((page.getPageIndex() - 1) * page.getPageSize(), page.getPageSize()));
        return page;
    }

    @Override
    public Page qryAllOrderByPage(Integer currentPageNo, BorrowOrderQuery borrowOrderQuery) {
        Page page = new Page();
        page.setPageIndex(currentPageNo);
        String startTime = "";
        String endTime = "";
        if (borrowOrderQuery.getQueryTime() != null && !borrowOrderQuery.getQueryTime().equals("")) {
            startTime = borrowOrderQuery.getQueryTime().substring(0, 10);
            System.out.println(startTime);
            endTime = borrowOrderQuery.getQueryTime().substring(13, 23);
            System.out.println(endTime);
        }
        page.setTotalCount(borrowOrderMapper.qryConditionCount(borrowOrderQuery.getQueryName(), borrowOrderQuery.getQueryPhone(), startTime, endTime, borrowOrderQuery.getQueryType(), borrowOrderQuery.getQueryBoType(), borrowOrderQuery.getQueryBoTypeList()));
        page.setRows(borrowOrderMapper.qryAllOrderByPage((page.getPageIndex() - 1) * page.getPageSize(), page.getPageSize(),
                borrowOrderQuery.getQueryName(), borrowOrderQuery.getQueryPhone(), startTime, endTime, borrowOrderQuery.getQueryType(), borrowOrderQuery.getQueryBoType(), borrowOrderQuery.getQueryBoTypeList()));
        return page;
    }

    @Override
    public BorrowOrder qryByID(int id) {
        return borrowOrderMapper.qryByID(id);
    }

    @Override
    public Page qryAllContract(Integer currentPageNo, BorrowOrderQuery borrowOrderQuery) {
        Page page = new Page();
        page.setPageIndex(currentPageNo);
        String startTime = "";
        String endTime = "";
        if (borrowOrderQuery.getQueryTime() != null && !borrowOrderQuery.getQueryTime().equals("")) {
            startTime = borrowOrderQuery.getQueryTime().substring(0, 10);
            System.out.println(startTime);
            endTime = borrowOrderQuery.getQueryTime().substring(13, 23);
            System.out.println(endTime);
        }
        page.setTotalCount(borrowOrderMapper.qryContractCount(borrowOrderQuery.getQueryBoId(), borrowOrderQuery.getQueryName(), borrowOrderQuery.getQueryContractID(), startTime, endTime, borrowOrderQuery.getQueryType(), borrowOrderQuery.getQueryBoType(), borrowOrderQuery.getQueryBoTypeList()));
        page.setRows(borrowOrderMapper.qryAllContract((page.getPageIndex() - 1) * page.getPageSize(), page.getPageSize(), borrowOrderQuery.getQueryBoId(), borrowOrderQuery.getQueryName(), borrowOrderQuery.getQueryContractID(), startTime, endTime, borrowOrderQuery.getQueryType(), borrowOrderQuery.getQueryBoType(), borrowOrderQuery.getQueryBoTypeList()));
        return page;
    }

    @Override
    public int modifyBorrowOrderType(BorrowOrder borrowOrder) {
        return borrowOrderMapper.modifyBorrowOrderType(borrowOrder);
    }
}
